<template>
    <div class="mainDiv">
        <div class="rowHead">
            <el-select v-model="page.shopId" @change="getList" v-qx="permission.status">
                <el-option v-for="s in shopList" :label="s.name" :value="s.id" :key="s.id">
                </el-option>
            </el-select>
            <el-select v-model="page.orderType" v-qx="permission.status">
                <el-option v-for="s in orderTypeList" :label="s.name" :value="s.id" :key="s.id">
                </el-option>
            </el-select>
            <el-input style="width: 200px" placeholder="搜索订单编号" @keyup.enter.native="getList" v-model="page.search">
                <i slot="suffix" class="el-icon-search" style="line-height: 40px;width: 25px;cursor: pointer;" @click="getList"></i>
            </el-input>
        </div>
        <el-table :data="list" :stripe="true" height="100%">
            <el-table-column prop="order_sn" label="订单编号" width="165"></el-table-column>
            <el-table-column prop="dname" label="所属分店"></el-table-column>
            <el-table-column prop="isdisabled" label="状态">
                <template slot-scope="scope">
                    <Tags :typeValue="scope.row.status" typeName="orderStatus" :tagStyle="{color: '#fff'}"></Tags>
                </template>
            </el-table-column>
            <el-table-column prop="addtime" label="添加日期" :show-overflow-tooltip="true">
                <template slot-scope="scope">
                    {{scope.row.addtime|dateTime}}
                </template>
            </el-table-column>
            <el-table-column label="产品操作" width="250">
                <template slot-scope="scope">
                    <el-button-group>
                        <el-tooltip content="修改单据日期" placement="left" :open-delay="800" v-qx="permission.edit">
                            <el-button type="warning" icon="edit" size="mini" @click="edit(scope.row)">修改单据日期</el-button>
                        </el-tooltip>
                    </el-button-group>
                </template>
            </el-table-column>
        </el-table>
        <div class="block center bg-light">
            <el-pagination @size-change="sizeChange" @current-change="currentChange" :current-page="page.pages" :page-sizes="[15, 30, 50, 100]" :page-size="page.limits" layout="total, sizes, prev, pager, next, jumper" :total="total">
            </el-pagination>
        </div>
        <el-dialog title="修改单据日期" :visible.sync="centerDialogVisible" width="30%">
            <el-alert title="注：请慎重修改单据日期，单据日期修改后将会对财务帐据和员工工资以及业绩产生影响。" type="warning" show-icon :closable="false">
            <div style="margin: 5px">单号: {{selectRow.order_sn}}</div>
            <div style="margin: 5px">当前单据日期: {{selectRow.addtime|dateTime}}</div>
            <div style="margin: 5px">修改后日期:
                <el-date-picker size="mini" v-model="nowTime" type="date" placeholder="选择日期" style="margin-left: 5px">
            </el-date-picker></div>
            </el-alert>
            <span slot="footer" class="dialog-footer">
            <el-button @click="centerDialogVisible = false" size="mini">取 消</el-button>
            <el-button type="primary" @click="submit" size="mini">确 定</el-button>
          </span>
        </el-dialog>
    </div>
</template>
<script>
import C from '@/common/common.js'
import Tags from '@/components/orderTags.vue'
export default {
  name: 'orderList',
  data () {
    return {
      list: [],
      total: 0,
      page: {
        pages: 1,
        limits: 15,
        search: '',
        shopId: '',
        orderType: ''
      },
      shopList: [],
      orderTypeList: [{
        id: 1,
        name: '开卡单'
      }, {
        id: 2,
        name: '流水单'
      }, {
        id: 3,
        name: '充值单'
      }],
      permission: {
        add: 'goodscategory_add',
        status: 'goodscategory_status',
        edit: 'goodscategory_edit',
        unstop: 'goodscategory_unstop'
      },
      centerDialogVisible: false,
      selectRow: {},
      nowTime: ''
    }
  },
  async mounted () {
    this.getList()
    // 获取分店列表
    let shopList = await C.ajax('/organization/shop/shoplist', {
      pages: 1,
      limits: 100,
      search: '',
      zt: 0
    }, 'post')
    if (shopList) {
      this.shopList = shopList.data
    }
    console.log(shopList.data)
  },
  methods: {
    edit: async function (row) {
      /* let res = await C.openBrowserWindow('/editOrder', { row: row }, {
                transparent: true,
                frame: false,
                width: 650,
                height: 400,
                useSpa: true,
                spaModel: 'organization'
            })
            console.log(res)
            if (res) {
                C.success(res.data)
                this.getList()
            } */
      this.centerDialogVisible = true
      this.selectRow = row
    },
    async submit () {
      let res = await C.ajax('/organization/order/changeOrderTimes', {orderid: this.selectRow.id, nowTime: this.nowTime}, 'post')
      console.log(res)
    },
    sizeChange: function (val) {
      this.page.limits = val
      this.getList()
    },
    currentChange: function (val) {
      this.page.pages = val
      this.getList()
    },
    getList: async function () {
      let that = this
      let data = await C.ajax('/organization/order/getShopOrder', this.page)
      if (data) {
        that.list = data.data
        that.total = data.count
      }
    }
  },
  components: { Tags }
}
</script>
<style>
.mb20 {
    margin-bottom: 20px;
}
</style>